<?php

namespace common\modules\user\controllers\backend;

use common\components\TreeNodeController;
use common\modules\user\models\backend\GroupTree;
use common\widgets\tree\TreeView;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;

/**
* GroupController implements the CRUD actions for Group model.
*/
class GroupController extends TreeNodeController
{

    /**
     * {@inheritdoc}
     */
    public function init()
    {
        parent::init();
        $this->defaultPostData = ArrayHelper::merge($this->defaultPostData, [
            'modelClass' => GroupTree::className(),
        ]);
    }

    /**
     * 首页
     *
     * @return string
     */
    public function actionIndex()
    {
        return $this->render(TreeView::DEFAULT_FORM_VIEW, [
            'title' => Yii::t('backend/user', 'User Group Manage'),
            'treeConfig' => [
                'query' => GroupTree::find()->addOrderBy('root, lft'),
                'headingOptions' => ['label' => Yii::t('backend/user', 'User Group Manage')],
                'fontAwesome' => true,
                'isAdmin' => true,
                'displayValue' => 1,
                'nodeActions' => [
                    'save' => Url::to(['save']),
                    'manage' => Url::to(['manage']),
                    'remove' => Url::to(['remove']),
                    'move' => Url::to(['move']),
                ],
                'softDelete' => true,
                'cacheSettings' => [
                    'enableCache' => true,
                ]
            ],
        ]);
    }
}
